package com.hxzy.projectssmplus.controller;

import com.hxzy.projectssmplus.entity.HouseSellingQuali;
import com.hxzy.projectssmplus.service.HouseSellingQualiService;
import com.hxzy.projectssmplus.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class HouseSellingQualiController {

    @Autowired
    private HouseSellingQualiService houseSellingQualiService;

    /**
     * 根据新房id查询售卖资格
     * @param houseId
     * @return
     */
    @GetMapping("/house/sellingquali/query/{houseId}")
    public AjaxResult queryByNewHouseId(@PathVariable(value = "houseId") Long houseId) {
        List<HouseSellingQuali> list = this.houseSellingQualiService.queryByNewHouseId(houseId);
        return AjaxResult.success_data(list);
    }

    /**
     * 售卖资格新增
     * @param houseSellingQuali
     * @return
     */
    @PostMapping(value = "/house/sellingquali/add")
    public AjaxResult add(@RequestBody HouseSellingQuali houseSellingQuali) {
        System.out.println("新增获取到的参数    "+houseSellingQuali.getHouseNewId());
//        boolean save = this.houseSellingQualiService.save(houseSellingQuali);
//
//        if (save) {
//            return AjaxResult.success("新增成功");
//        } else {
//            return AjaxResult.error("新增失败");
//        }
        Integer integer = this.houseSellingQualiService.addSell(houseSellingQuali);
        return integer>0? AjaxResult.success("sell新增数据成功"):AjaxResult.error("sell新增数据失败");
    }

    /**
     * 售卖资格修改
     * @param houseSellingQuali
     * @return
     */
    @PostMapping(value = "/house/sellingquali/edit")
    public AjaxResult edit(@RequestBody HouseSellingQuali houseSellingQuali) {
        System.out.println("sell修改获取的参数   "+houseSellingQuali.getId());
        boolean updateById = this.houseSellingQualiService.updateById(houseSellingQuali);

        if (updateById) {
            return AjaxResult.success("修改成功");
        } else {
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 售卖资格删除
     * @param id
     * @return
     */
    @PostMapping(value = "/house/sellingquali/delete/{id}")
    public AjaxResult delete(@PathVariable(value = "id") int id) {
        System.out.println("删除收到的id     "+id);
        boolean removeById = this.houseSellingQualiService.removeById(id);

        if (removeById) {
            return AjaxResult.success("删除成功");
        } else {
            return AjaxResult.error("删除失败");
        }
    }
}
